package com.xinke.module.system.mapper.oauth2;

import com.xinke.component.common.pojo.PageResult;
import com.xinke.component.mybatis.mybatis.core.query.LambdaQueryWrapperExt;
import com.xinke.component.mybatis.mybatis.core.mapper.BaseMapperExt;
import com.xinke.module.system.model.entity.oauth2.OAuth2ClientDO;
import org.apache.ibatis.annotations.Mapper;
import com.xinke.module.system.model.vo.oauth2.*;

/**
 * OAuth2 客户端 Mapper
 *
 * @author yzx
 */
@Mapper
public interface OAuth2ClientMapper extends BaseMapperExt<OAuth2ClientDO> {

    default PageResult<OAuth2ClientDO> selectPage(OAuth2ClientPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperExt<OAuth2ClientDO>()
                .eqIfPresent(OAuth2ClientDO::getClientNo, reqVO.getClientNo())
                .eqIfPresent(OAuth2ClientDO::getClientSecret, reqVO.getClientSecret())
                .likeIfPresent(OAuth2ClientDO::getClientName, reqVO.getClientName())
                .eqIfPresent(OAuth2ClientDO::getClientLogo, reqVO.getClientLogo())
                .eqIfPresent(OAuth2ClientDO::getClientDesc, reqVO.getClientDesc())
                .eqIfPresent(OAuth2ClientDO::getClientStatus, reqVO.getClientStatus())
                .eqIfPresent(OAuth2ClientDO::getAccessTokenValiditySeconds, reqVO.getAccessTokenValiditySeconds())
                .eqIfPresent(OAuth2ClientDO::getRefreshTokenValiditySeconds, reqVO.getRefreshTokenValiditySeconds())
                .eqIfPresent(OAuth2ClientDO::getRedirectUri, reqVO.getRedirectUri())
                .eqIfPresent(OAuth2ClientDO::getAuthorizedGrantTypes, reqVO.getAuthorizedGrantTypes())
                .eqIfPresent(OAuth2ClientDO::getAuthScope, reqVO.getAuthScope())
                .eqIfPresent(OAuth2ClientDO::getAutoApproveScopes, reqVO.getAutoApproveScopes())
                .eqIfPresent(OAuth2ClientDO::getAuthorities, reqVO.getAuthorities())
                .eqIfPresent(OAuth2ClientDO::getResourceIds, reqVO.getResourceIds())
                .eqIfPresent(OAuth2ClientDO::getAdditionalInformation, reqVO.getAdditionalInformation())
                .orderByDesc(OAuth2ClientDO::getClientId));
    }

    default OAuth2ClientDO selectByClientNo(String clientNo) {
        return selectOne(OAuth2ClientDO::getClientNo, clientNo);
    }

}